using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace LeChat
{
    public partial class LogInForm : Form
    {
        public LogInForm()
        {
            InitializeComponent();
        }
        /// <summary>
        /// a constructor designed to use saved 
        /// login data
        /// </summary>
        /// <param name="address"></param>
        /// <param name="port"></param>
        public LogInForm(IPAddress address, int port)
        {
            InitializeComponent();

            if (address!=null)
            {
                txtAddress.Text = address.ToString();
            }

            if (port>0 && port<65535)
            {
                numericUpDown1.Value = port;
            }
        }

        #region Porpeties & Data members

        private int port;

        public int Port
        {
            get { return port; }
           
        }

        private IPAddress address;

        public IPAddress Address
        {
            get { return address; }
        }

        private DialogResult result;

        public DialogResult Result
        {
            get { return result; }
           
        }



        #endregion


        private void btnConnect_Click(object sender, EventArgs e)
        {
            //transfers the data fro the form to the data
            //members
            try
            {                
                address = IPAddress.Parse(txtAddress.Text);
                port =(int)numericUpDown1.Value;
            }
            catch (FormatException exp)
            {
                MessageBox.Show("Invalid IP Adress","Oh No!",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
                
            }
            result = DialogResult.OK;
            this.Close();
            
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            result = DialogResult.Cancel;
            this.Close();
        }
    }
}